#!/usr/bin/python

from elasticsearch import Elasticsearch
from datetime import datetime
import json

es_cluster_ips = ['localhost:9200']
es = Elasticsearch(es_cluster_ips)

# GET example
def get_employee(employee_id):
	# Example of GET action
	result = es.get(index='megacorp', doc_type='employee', id=str(employee_id)) 
	print result['_source']

# PUT example
def put_employee(employee_id, employee_info):
	result = es.index(index='megacorp', doc_type='employee', id=str(employee_id), body=employee_info)
	print result['created']

# Search exampe
def search_employee(employee_id):
    result = es.search(index='megecorp', body={"query": {"match": {"_id":
                                                                   employee_id}}})
    print result

def show_health():
	result = es.cluster.health(index='megacorp')
	print result

# Example of Put action
doc = {
    "first_name" :  "Cornell",
    "last_name" :   "Greene",
    "age" :         30,
    "about":        "Trying to get this to work",
    "interests":  [ "forestry" ]
}

employee_id = '4'
#get_employee(1)
#put_employee(4, doc)
print "Searching for employee " + employee_id
search_employee(employee_di)
show_health()
